'''
Author: Zhang Wei
Date: 2023-11-04 12:34:17
LastEditors: Zhang Wei
LastEditTime: 2023-11-04 16:23:16
FilePath: \auto-test\01-project\02-login\index.py
Description:
Word: There is nothing either good or bad, but thinking makes it so.
'''
import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By

from tools.common import getPageByUrl;

# print("当前最新版本的webdriver:" + ChromeDriverManager().install())

options = webdriver.ChromeOptions()

# 这种写法好像不持支，我只能把 chromeDriver 的位置写道环境变量里了
# driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=options)
# 这个是绝对路径
driver = webdriver.Chrome(options=options)

# driver.get("https://bpm.geelycv.com/custom-webapp/gcvLogin.html") # 正式环境
driver.get("https://bpm.geelycv-test.com/custom-webapp/gcv-bpm/login.html") # 测试环境

# 登录
driver.find_element(By.CSS_SELECTOR, '.username input').send_keys('Zhendong.He2')
driver.find_element(By.CSS_SELECTOR, '.password input').send_keys('$Hzd$0727!')
driver.find_element(By.CSS_SELECTOR, '.submit').click()

time.sleep(3)

# 进入 新建流程
# newWorkflow = "https://bpm.geelycv-test.com/wui/index.html#/main/workflow/add?menuIds=1,12&menuPathIds=1,12&_key=g4xp1x"
# driver.get(newWorkflow)
# time.sleep(2)

# 进入 流程监控
processMonitoringPage = "https://bpm.geelycv-test.com/wui/index.html#/main/workflow/monitor?menuIds=1,101&menuPathIds=1,101&_key=51q27m"

# 所属路径选择
# driver.find_element(By.CSS_SELECTOR, '#span > div.ant-input-group-wrap > button').click();

# text = driver.find_element(By.CSS_SELECTOR, '#weareqtop_w1kk3v_1699002565177 > div.ant-row.wea-new-top-req > div > div.wea-new-top-req-title-text.wea-f14 > div').text;
# print(text)
print("当前页面url："+driver.current_url)
# newPageDriver = getPageByUrl(driver, processMonitoringPage)
driver.get(processMonitoringPage)
# newPageDriver = driver
print("新页面url："+driver.current_url)

time.sleep(5)

# 打开弹窗
print(driver.find_elements(By.CSS_SELECTOR, '#span > div.ant-input-group-wrap > button').__le__)
driver.find_elements(By.CSS_SELECTOR, '#span > div.ant-input-group-wrap > button')[1].click()

time.sleep(1)

strFindInput = ".ant-modal-content .advance-search-wrapper .ant-input-wrapper input";
driver.find_element(By.CSS_SELECTOR, strFindInput).send_keys("基建技改（装备及工程）类项目立项/变更流程")
driver.find_element(By.CSS_SELECTOR, ".ant-modal-content .advance-search-wrapper .ant-search-btn.wea-input-focus-btn").click();

# 选择
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, "div.ant-modal-wrap.wea-browser-modal.wea-browser-single.wea-browser-test-single.wea-browser-table-cursor.no-top > div > div.ant-modal-content > div.ant-modal-body > div > div.ant-spin-nested-loading > div > div:nth-child(2) > div > div > div > div > div > div > div > span > div.ant-table-body > table > tbody > tr > td:nth-child(1) > div").click()

# 搜索
driver.find_element(By.CSS_SELECTOR, "div.wea-new-top-content > div.wf-query-btns > button.ant-btn.ant-btn-primary").click();

# 获取返回的结果
for request in driver.requests:
    if request.response:
        print('[status_code)]: ' + request.response.status_code)
        
        # 判断接口是否包含 /api/ec/dev/table/datas
        if ("/api/ec/dev/table/datas" in request.url & request.response.status_code == "200"):
            print(request.response.body)

# 最大化浏览器
# driver.maximize_window()
time.sleep(99999)
driver.close()
